#!/usr/bin/env python
#-*- coding:utf-8 -*-

import sys, getopt
from IEDModel import IEDChat
from IEDProxy import IEDProxy
from GTKUI import PyChatGTK
from getpass import getpass

try:
	import gtk
except:
	sys.exit(1)


if __name__ == '__main__':
	try:
		opts, args = getopt.getopt(sys.argv[1:], 'u:p:', ['username=', 'password='])
	except getopt.GetoptError:
		print 'Unknown command line flags'
		sys.exit(2)
	
	username, password = '', ''
	for opt, arg in opts:
		if opt in ('-u', '--username'):
			username = arg
		
		elif opt in ('-p', '--password'):
			password = arg
	
	username = username or str(raw_input('Login : '))
	password = password or str(getpass('Password : '))
	
	ui = PyChatGTK()
	proxy = IEDProxy()
	
	chat = IEDChat(proxy, ui)
	chat.connect(username, password)
	chat.mainloop()
	gtk.main()


